package jmine.tec.report.script;

import java.io.OutputStream;

import jmine.tec.report.api.Report;
import jmine.tec.script.persistent.context.impl.AbstractScriptExecutionContext;

/**
 * Contexto de execução de um script de renderização de relatório.
 * 
 * @author lundberg
 */
public class ExportReportScriptExecutionContextImpl extends AbstractScriptExecutionContext<OutputStream> implements
        ExportReportScriptExecutionContext {

    private static final String STREAM = "stream";

    private static final String REPORT = "report";

    private static final String TRACER = "tracer";

    private StringBuilder tracer = new StringBuilder();

    private OutputStream result;

    /**
     * Construtor
     */
    public ExportReportScriptExecutionContextImpl() {
        // OK
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void beforeExecution() {
        super.beforeExecution();
        this.getParameters().putParameter(TRACER, this.tracer);
    }

    /**
     * {@inheritDoc}
     */
    public OutputStream getResult() {
        return this.result;
    }

    /**
     * {@inheritDoc}
     */
    public String getTracer() {
        return this.tracer.toString();
    }

    /**
     * {@inheritDoc}
     */
    public ExportReportScriptExecutionContext prepare(OutputStream outputStream, Report report) {
        this.result = outputStream;
        this.getParameters().putParameter(STREAM, this.result);
        this.getParameters().putParameter(REPORT, report);
        return this;
    }
}
